#include "../lib/capture.hpp"
#include "boost/thread.hpp"
#include <iostream>
#include <cstdlib>
#include <transport.hpp>
#include <pipc.hpp>

using namespace std;

int main()
{
    pipc::Pipc* settings = pipc::Pipc::Instance();
    settings->initialize("pipc.xml", "capture");
    settings->start();
    settings->subscribe("capture.resolution",false);
    settings->subscribe("motion.relarea", true);

    pland::Chain::Chain_Queue qB;
    pland::Chain::Chain_Queue qG;
    pland::Chain::Chain_Queue qR;

    qB.net = "CaptureB";
    qB.sink  = 1;
    qB.queue = pland::SharedDQueue(new pland::DQueue(10));
    qB.type = pland::Chain::SINK;

    qG.net = "CaptureG";
    qG.sink  = 2;
    qG.queue = pland::SharedDQueue(new pland::DQueue(10));
    qG.type = pland::Chain::SINK;

    qR.net = "CaptureR";
    qR.sink  = 3;
    qR.queue = pland::SharedDQueue(new pland::DQueue(10));
    qR.type = pland::Chain::SINK;


    std::vector <pland::Chain::Chain_Queue> queues;
    queues.push_back(qB);
    queues.push_back(qG);
    queues.push_back(qR);

    Capture c(1, qB.queue,qG.queue,qR.queue);

    kport::Transport transp("route.xml");
    transp.loadQueues(queues);
    transp.startListner();
    std::string temp;
    cout << "Start?";
    cin >> temp;
    boost::thread t(&Capture::start, &c);
    transp.connectOutbound();
    transp.start();
    cout << "Stop?";

    cin >> temp;
    t.interrupt();
    t.join();
    transp.stop();
    settings->stop();
    return 0;
}
